<?php

/**
 * Description of Article_model
 *
 * @author hoangle
 */
class Article_model extends CI_Model {

//put your code here
    function __construct() {
        parent::__construct();
    }
    
    function arc_GetNewestArticle() {
        try {

            $this->db->select('c.*');
            $this->db->from('content AS c');
            $this->db->join('categories AS cat', 'cat.id = c.catid');
            $this->db->join('categories AS pcat', 'pcat.id = cat.parent_id');
            $this->db->where(array('pcat.path <> "uncategorised"' => NULL, 'pcat.path IS NOT NULL' => NULL));
            $this->db->limit(10);
            $query = $this->db->get();
            //echo $this->db->last_query();
            return $query->result();
        } catch (Exception $e) {
            print_r($e);
        }
    }
    
    function arc_GetNewestByCate($arrParams) {
        try {
            $this->db->select('c.*');
            $this->db->from('content AS c');
            $this->db->join('categories AS cat', 'cat.id = c.catid');
            $this->db->join('categories AS pcat', 'pcat.id = cat.parent_id');
            $this->db->where(array('pcat.path <> "uncategorised"' => NULL, 'pcat.path IS NOT NULL' => NULL));
            $this->db->where(array('pcat.id' => $arrParams['catid']));
            $this->db->limit(10);
            $query = $this->db->get();
            //echo $this->db->last_query();
            return $query->result();
        } catch (Exception $e) {
            print_r($e);
        }
    }

//////////////////////////////////////////////////////////////////////////////////
//                                  LIST PROCESS                                //
//////////////////////////////////////////////////////////////////////////////////
    /**
     * @desc Get list news by catid
     * @param <type> $arrParams
     * @return <type>
     */
    function arc_lGetNewestByCatID($arrParams) {
        try {
            $this->db->select('c.*');
            $this->db->from('content AS c');
            $this->db->where(array("catid IN(" . $arrParams['catid'] .")" => NULL));            
            $this->db->order_by('publish_up', 'DESC');
            $this->db->limit($arrParams['limit']);
            $query = $this->db->get();
            return $query->result();
        } catch (Exception $e) {
            print_r($e);
            return false;
        }
    }

}

?>
